﻿// Nail.ProgressForm Library
// Nail framework
//
// Copyright © Frank Nagl, 2008
// admin@franknagl.de
// www.franknagl.de
//
namespace Picturez
{
    using System.Drawing;
    using System.Windows.Forms;

    /// <summary>
    /// Provides a static form with a progress bar.
    /// </summary>
    public static class ProgressForm
    {
        /// <summary>
        /// Inits a form and progress bar.
        /// </summary>
        /// <param name="text">The text and caption of the form.</param>
        /// <param name="icon">The icon of the form.</param>
        /// <param name="start">The start value of the progress bar.</param>
        /// <param name="end">The end value of the progress bar.</param>
        /// <param name="step">The step size of the progress bar.</param>
        /// <returns>Progress bar of the form.</returns>
        /// <remarks>
        /// Example using:
        /// <code>
        /// // Init form with progress bar, which will be returned
        /// ProgressBar bar = ProgressForm.InitFormAndProgressBar("Convert", null, 0, 100, 1);
        /// // Perform a progress step of the progress bar
        /// bar.PerformStep();
        /// // Close the form
        /// bar.Parent.Dispose();
        /// </code>
        /// </remarks>
        public static ProgressBar InitFormAndProgressBar(string text, Icon icon,
            int start, int end, int step)
        {
            Form updateForm = new Form();
            ProgressBar bar = new ProgressBar();
            Label label = new Label();
            updateForm.Controls.Add(bar);
            updateForm.Controls.Add(label);

            //init the form
            updateForm.Text = text;
            updateForm.Width = 300;
            updateForm.Height = 200;
            updateForm.BackColor = Color.Lavender;
            updateForm.StartPosition =
                FormStartPosition.CenterScreen;

            //init the icon
            updateForm.Icon = icon;

            //init the label
            label.Text = text;
            label.AutoSize = true;
            label.Location = new Point(100, 30);

            //init the progressBar
            bar.Location = new Point(100, 70);
            bar.Value = start;
            bar.Maximum = end;
            bar.Step = step;

            updateForm.Show();
            updateForm.Refresh();
            return bar;
        }
    }
}
